﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BUS;
using DTO;

namespace GUI
{
    public partial class frmTraCuuPhieuNhapHang : Form
    {
        public frmTraCuuPhieuNhapHang()
        {
            InitializeComponent();
        }

        private void frmTraCuuPhieuNhapHang_Load(object sender, EventArgs e)
        {
            hienthidanhsachphieunhap();
            hienthimaphieunhap();
            hienthitennhacungcap();
        }
        public void hienthidanhsachphieunhap()
        {
            List<PhieuNhapHangDTO> ds;
            PhieuNhapHangBUS bus = new PhieuNhapHangBUS();
            ds = bus.LayDanhSachPhieuNhapHang();
            this.dgvdsphieunhap.Rows.Clear();
            for (int i = 0; i <= ds.Count - 1; i++)
            {
                this.dgvdsphieunhap.Rows.Add(ds[i].MaPhieuNhap, ds[i].MaNhaCungCap, ds[i].NgayNhap, ds[i].ThanhToan, ds[i].ConNo);
            }
        }
        public void hienthimaphieunhap()
        {
            List<PhieuNhapHangDTO> ds;
            PhieuNhapHangBUS bus = new PhieuNhapHangBUS();
            ds = bus.LayDanhSachPhieuNhapHang();
            this.cbmaphieunhap.Items.Clear();
            for (int i = 0; i <= ds.Count - 1; i++)
            {
                this.cbmaphieunhap.Items.Add(ds[i].MaPhieuNhap);
            }
            this.cbmaphieunhap.ValueMember = "MaPhieuNhap";
            this.cbmaphieunhap.DisplayMember = "MaPhieuNhap";
        }
        public void hienthitennhacungcap()
        {
            List<NhaCungCapDTO> ds;
            NhaCungCapBUS bus = new NhaCungCapBUS();
            ds = bus.GetNhaCungCapAll();
            this.cbnhacungcap.Items.Clear();
            this.cbnhacungcap.ValueMember = "MaNhaCungCap";
            this.cbnhacungcap.DisplayMember = "TenNhaCungCap";
            for (int i = 0; i <= ds.Count - 1; i++)
            {
                cbnhacungcap.Items.Add(ds[i].TenNhaCungCap);
            }

        }

        private void bttracuu_Click(object sender, EventArgs e)
        {
            string maphieunhap = this.cbmaphieunhap.Text;
            string tennhacungcap = this.cbnhacungcap.Text;

            DateTime tungay = dtptungay.Value;
            DateTime denngay = dtpdenngay.Value;


            PhieuNhapHangBUS bus = new PhieuNhapHangBUS();
            List<PhieuNhapHangDTO> ds = bus.Tra_cuu_phieu_nhap_hang(maphieunhap, tennhacungcap, tungay, denngay);

            this.dgvdsphieunhap.Rows.Clear();
            for (int i = 0; i <= ds.Count - 1; i++)
            {
                this.dgvdsphieunhap.Rows.Add(ds[i].MaPhieuNhap, ds[i].MaNhaCungCap, ds[i].NgayNhap, ds[i].ThanhToan, ds[i].ConNo);
            }
        }

        private void btnlammoi_Click(object sender, EventArgs e)
        {
            this.cbmaphieunhap.Text = "";
            this.cbnhacungcap.Text = "";
        }

        private void btnexit_Click(object sender, EventArgs e)
        {
            //DialogResult dlr = MessageBox.Show("Bạn muốn thoát khỏi chương trình?", "Warnning", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            //if (dlr == DialogResult.Yes)
            //    this.Close();
            Close();
        }
    }
}
